from typing import List

from domain.note.noteDomain import NoteDomain
from util.aop.ormProxy import OrmProxy, Select, Insert, Update, Delete
from util.aop.proxy import ProxyFactory
from util.singleton import Singleton


@Singleton
@ProxyFactory(OrmProxy)
class NoteDao:
    @Select("""
    select note_id, note_date, start_time, end_time, note_type, note_content, create_time, update_time
    from note_note where 1=1
    <if test="noteDate">and note_date = #{noteDate}</if>
    <if test="noteType">and note_type = #{noteType}</if>
    <if test="noteContent">and note_content like concat('%', #{noteContent}, '%') </if>
    <if test="startTime and endTime">and start_time >= #{startTime} and end_time <= #{endTime}</if>
    """,
            List[NoteDomain])
    def list4Table(self, noteDate, noteType, noteContent, startTime, endTime, **kwargs):
        pass

    @Insert("""insert into note_note(note_date,start_time,end_time,note_type,note_content) values(
    #{domain.noteDate},#{domain.startTime},#{domain.endTime},#{domain.noteType},#{domain.noteContent})""")
    def add(self, domain: NoteDomain):
        pass

    @Update("""update note_note set 
    <if test="domain.noteDate">note_date=#{domain.noteDate},</if>
    <if test="domain.startTime">start_time=#{domain.startTime},</if>
    <if test="domain.endTime">end_time=#{domain.endTime},</if>
    <if test="domain.noteType">note_type=#{domain.noteType},</if>
    <if test="domain.noteContent">note_content=#{domain.noteContent},</if>
    update_time=sysdate()
    where note_id=#{domain.noteId}""")
    def update(self, domain: NoteDomain):
        pass

    @Delete("""delete from note_note where note_id=#{noteId}""")
    def delete(self, noteId):
        pass


if __name__ == '__main__':
    dao = NoteDao()
    OrmProxy.startPage(2, 5)
    res = dao.list4Table(typeId=1)
    for note in res:
        print(note)
    print(OrmProxy.getTotal(res))
    OrmProxy.startPage(2, 10)
    res = dao.list4Table(typeId=1)
    for note in res:
        print(note)
    print(OrmProxy.getTotal(res))
    # print(dao.add(domain=NoteDomain(noteDate='2022/3/16',startTime='22:00:00',endTime='23:00:00',
    #                                 noteType=1,noteContent='')))
    print(dao.update(domain=NoteDomain(noteId=19)))
    # print(dao.delete(noteId=20))
